export type Notice = {
  key: string
  value: string | number | boolean | null

  // 消息通知栏相关
  description: string
  closable: boolean
  color: NoticeColor
  ranking: number // 优先级
  triggerActionImmediate?: boolean // 是否立即触发消息Action

  // 匹配条件
  brand: string
  type: string
  vib: string

  // 消息Action相关 (属性为null时，无Action)
  action: NoticeAction | null
}

export enum NoticeColor {
  Normal = 0, // 一般消息
  Warning = 1, // 黄色警告消息
  Danger = 2, // 红色警告消息
}

export type NoticeAction =
  | ShowModalAction
  | RichTextAction
  | ToPageAction
  | ToOtherMPAction
  | CallPhoneAction
  | DrumCleanAction
  | InvokeMethodAction
  | Custom1Action

export enum ActionType {
  ShowModal = 1, // 弹窗展示info
  RichText = 2, // 打开富文本
  ToPage = 3, // 跳转本小程序
  ToOtherMP = 4, // 跳转其他小程序
  CallPhone = 5, // 拨打电话
  DrumClean = 6, // 筒清洁特殊处理
  InvokeMethod = 7, // 调用本小程序方法
  Custom1 = 8, // 自定义1
}

export type BaseAction = {
  // Action类型
  type: ActionType

  // 链接文本
  linkText: string // "查看详情" | "去购买" | "去升级" | ......
}

/**
 * 弹窗展示info
 */
export type ShowModalAction = ModalInfoAction | ModalConfirmAction
type BaseModalAction = BaseAction & {
  type: ActionType.ShowModal
  title: string // "家电已离线"
  modalType: ModalType // 弹框确认类型 (仅关闭 / Acknowledge & Reject)
  description: ModalDescriptionRow[] // 弹框内容 (每行一项)
  descriptionType?: ModalDescriptionType // 弹框内容类型 (普通内容 / 带序号的步骤指引)
  descriptionAlign?: ModalDescriptionAlign // 对齐方式 (左中右对齐)
}
export type ModalInfoAction = BaseModalAction & {
  modalType: ModalType.Dismiss // 弹框确认类型
  dismissText: string // 弹框关闭按钮文本
}
export type ModalConfirmAction = ModalAcknowledgeAction | ModalDecisionAction
export type ModalAcknowledgeAction = BaseModalAction & {
  modalType: ModalType.Acknowledge // 弹框确认类型
  acknowledgeText: string // 弹框确认按钮文本
}
export type ModalDecisionAction = BaseModalAction & {
  modalType: ModalType.Decision // 弹框确认类型
  acknowledgeText: string // 弹框确认按钮文本
  rejectText: string // 弹框取消按钮文本
}
export enum ModalType {
  Dismiss = 0, // 仅显示一个确定按钮 作用是关闭弹框
  Acknowledge = 1, // 仅显示一个确定按钮 作用是下发Acknowledge并关闭弹框
  Decision = 2, // 显示确定和取消按钮 作用是下发Acknowledge或Reject并关闭弹框
}
export type ModalDescriptionRow = {
  // 弹框内容 (每行一项)
  contents: Array<ModalContent>
}
export type ModalContent = ModalText | ModalLink | ModalLandingLink | ModalImage
export type ModalText = {
  text: string
  // style?: string
}
export type ModalLink = {
  linkText: string
  method: string
}
export type ModalLandingLink = {
  linkText: string
  landingPage: string
}
export type ModalImage = {
  image: string
}
export enum ModalDescriptionType {
  Plain = 0, // 普通内容
  Step = 1, // 带序号前缀的指引步骤内容
}
export enum ModalDescriptionAlign {
  Left = 0, // 左对齐
  Center = 1, // 居中对齐
  Right = 2, // 右对齐
}

/**
 * 打开富文本
 */
export type RichTextAction = BaseAction & {
  type: ActionType.RichText
  articleId: string
  articleType: string
}

/**
 * 跳转本小程序
 */
export type ToPageAction = BaseAction & {
  type: ActionType.ToPage
  landingPage: string
}

/**
 * 跳转其他小程序
 */
export type ToOtherMPAction = BaseAction & {
  type: ActionType.ToOtherMP
  appid: string
  landingPage: string
}

/**
 * 拨打电话
 */
export type CallPhoneAction = BaseAction & {
  type: ActionType.CallPhone
  phoneNumber: string
  title: string
  description: ModalDescriptionRow[] // 弹框内容 (每行一项)
  dismissText: string // 弹框关闭按钮文本
}

/**
 * 筒清洁特殊处理
 */
export type DrumCleanAction = BaseAction & {
  type: ActionType.DrumClean
  title: string
  description: Array<{
    title: string
    subtitle: string
    cleaningLevelOne: DrumCleanLevel
    cleaningLevelTwo: DrumCleanLevel
  }>
}
type DrumCleanLevel = {
  cleanTitle: string
  productsTitle: string
  appid: string
  landingPage: string
}

/**
 * 自定义1
 */
export type InvokeMethodAction = BaseAction & {
  type: ActionType.InvokeMethod
  // 调用方法名
  method: string
  /**
   * [可选] 弹框数据
   */
  title?: string
  dismissText?: string
}

/**
 * 自定义2
 */
export type Custom1Action = BaseAction & {
  type: ActionType.Custom1
}
